package com.jiepos.mpos.biz.code.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.code.service.InfCnapsService;
import com.jiepos.mpos.common.entity.App_Inf_CnapsEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;


@Controller
@RequestMapping("cnaps")
public class InfCnapsController extends BaseController {
	
	@Autowired
	private InfCnapsService infCnapsService;
	
	/**
	 * 进入联行号信息列表页面
	 * @param request
	 * @param response
	 * @param pagination
	 * @param appInfCnapsEntity
	 * @return
	 */
	@RequestMapping("/getCnapsList.do")
	public ModelAndView getCnapsList(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination) {
		ModelAndView model = new ModelAndView("/module/code/cnaps/cnaps_list");		
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 查询联行号列表信息json数据
	 * @param request
	 * @param response
	 * @param pagination
	 * @param appInfCnapsEntity
	 * @return
	 */
	@RequestMapping("/getCnapsListJson.do")
	public @ResponseBody Map getCnapsListJson(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination, App_Inf_CnapsEntity appInfCnapsEntity) {
		return infCnapsService.getAppInfCnapsList(pagination, appInfCnapsEntity);	
	}
	
	/**
	 * 进入联行号信息详细页面
	 * @param request
	 * @param response
	 * @param pagination
	 * @param cnaps_uuid
	 * @return
	 */
	@RequestMapping("/getCnapsDetail.do")
	public ModelAndView getCnapsDetail(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination,String cnaps_uuid) {
		ModelAndView model = new ModelAndView("/module/code/cnaps/cnaps_detail");
		App_Inf_CnapsEntity appInfCnapsEntity=infCnapsService.getCnapsById(cnaps_uuid);				
		model.addObject("appInfCnapsEntity", appInfCnapsEntity);
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 保存联行号
	 * @param request
	 * @param response
	 * @param appInfCnapsEntity
	 * @return
	 */
	@RequestMapping("/saveCnaps.do")
	public ModelAndView saveCnaps(HttpServletRequest request, HttpServletResponse response,
			App_Inf_CnapsEntity appInfCnapsEntity) {
		infCnapsService.saveCnaps(appInfCnapsEntity, super.getLoginUser(request, response));		
		Map map=super.getLoginUser(request, response);	
		return new ModelAndView(new RedirectView("getCnapsList.do"), map);
	}

	/**
	 * 删除联行号信息
	 * @param request
	 * @param response
	 * @param cnaps_uuids
	 * @return
	 */
	@RequestMapping("/deleteCnapsByIds.do")
	public ModelAndView deleteCnapsByIds(HttpServletRequest request, HttpServletResponse response, String cnaps_uuids) {
		infCnapsService.deleteCnapsByIds(cnaps_uuids);		
		Map map=super.getLoginUser(request, response);  
		return new ModelAndView(new RedirectView("getCnapsList.do"), map);
	}
	
	/**
	 * 校验联行号
	 * @param request
	 * @param response
	 * @param appInfCnapsEntity
	 * @return
	 */
	@RequestMapping("/checkCnaps.do")
	public @ResponseBody String checkCnaps(HttpServletRequest request, HttpServletResponse response,
			App_Inf_CnapsEntity appInfCnapsEntity){		
		return infCnapsService.checkCnaps(appInfCnapsEntity);
	}
}
